<?php
/**
* Class Item.
*
* Implementation of the class Permiso.
*
* PHP version >= 5.1
*
* @category     FrameworkPunkuPHP
* @package      Model
* @author       Juan Carlos Torrico Rios
* @copyright    2010 Juan Carlos Torrico Rios
* @license      http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version      1.0
* @link         None
* @see          None
* @since        Available from the version  0.1 01-01-2010
* @deprecated   No
*/

/**
* Class Item
*
* Implementation of class Permiso.
*
* @category   WindowSI
* @package    Model
* @author     Juan Carlos Torrico Rios
* @copyright  2010 Juan Carlos Torrico Rios
* @license    http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version    1.0
* @link       None
* @see        None
* @since      Available from the version  0.1 01-01-2010
* @deprecated No
*/
    class Item {
     // {{{ Constants

    /**
     * Constant for represent all registers.
     *
     * @access private
     */
     const ALL = -1;
     const VALUE = 1;
     const NONE = 0;
     // Operations
     const INSERT = "INSERT TABLE ALM_ITEM";
     const UPDATE = "UPDATE TABLE ALM_ITEM";
     const DELETE = "DELETE TABLE ALM_ITEM";
     const SELECT = "SELECT TABLE ALM_ITEM";
    // }}}

    // {{{ atributos

    /**
     * Variable instance Data Base.
     *
     * @var DataBase
     * @access private
     */
        private  $instanceDataBase;
    // }}}

    // {{{ constructores

    /**
     * This is construct base of the class.
     *
     * A public constructor; initializes the variable $instanceDataBase.
     *
     */
        public function __construct( $instanceDataBase ) {
            $this->instanceDataBase = $instanceDataBase;
        }
    // }}}

    // {{{ metodos

    /**
     * The implementation method for query to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function getListItem($idItem = self::ALL){
            $result = null;
            $query = null;
            try{
                $query = "SELECT 	pk_id_item ,
                                        codigo_item ,
                                        codigo_fabrica,
                                        descripcion ,
                                        caracteristicas_especiales ,
                                        fk_id_unidad_medida ,
                                        cantidad ,
                                        costo_unitario ,
                                        precio_unitario ,
                                        fecha_vencimiento ,
                                        saldo_minimo ,
                                        fk_id_proveedor ,
                                        fk_id_archivo_imagen ,
                                        fecha_transaccion ,
                                        usuario_transaccion ,
                                        estado_registro ,
                                        transaccion_creacion ,
                                        transaccion_modificacion ,
                                        fk_id_empresa
                           FROM   alm_item 
                           WHERE  estado_registro = 'A' ";

                if( $idItem != self::ALL){
                $query = $query." AND pk_id_item = ?";
                $result = DataBase::getArrayListQuery($query, array($idItem), $this->instanceDataBase);
                }
                else{
                $result = DataBase::getArrayListQuery($query,array(), $this->instanceDataBase);
                }
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0941: '.$e->getMessage();
            }
            return $result;
        }

    /**
     * The implementation method for insert data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function insertItem($data){
            $result = null;
            $query = null;
            try{
                $query = "INSERT INTO 
                                alm_item( 	
                                        codigo_item ,
                                        codigo_fabrica,
                                        descripcion ,
                                        caracteristicas_especiales ,
                                        fk_id_unidad_medida ,
                                        cantidad ,
                                        costo_unitario ,
                                        precio_unitario ,
                                        fecha_vencimiento ,
                                        saldo_minimo ,
                                        fk_id_proveedor ,
                                        fk_id_archivo_imagen ,
                                        fecha_transaccion ,
                                        usuario_transaccion ,
                                        estado_registro ,
                                        transaccion_creacion ,
                                        transaccion_modificacion ,
                                        fk_id_empresa ) ".
                         "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, current_timestamp(), ?, 'A', ?, ?, ?)";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0932: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for delete data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function deleteItem($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE alm_item ".
                         "SET estado_registro = 'E', ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_transaccion = ? ".
                         "WHERE pk_id_item = ? ";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);

            }
            catch(PDOException $e){
                echo 'Error JF-Model-0943: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for update data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function updateItem($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE alm_item ".
                         "SET codigo_item  = ?, 
                            codigo_fabrica = ?, 
                            descripcion  = ?, 
                            caracteristicas_especiales  = ?, 
                            fk_id_unidad_medida  = ?, 
                            cantidad  = ?,         
                            costo_unitario  = ?, 
                            precio_unitario  = ?, 
                            fecha_vencimiento  = ?, 
                            saldo_minimo  = ?, 
                            fk_id_proveedor  = ?, 
                            fk_id_archivo_imagen = ?,  ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_transaccion = ?, fk_id_empresa= ?".
                         "WHERE pk_id_proveedor = ? ";

                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0944: '.$e->getMessage();
            }
            return $result;
        }
     // }}}
    }
?>